package com.shop2cn.iapi.cdfgeteway.service;

import com.shop2cn.iapi.cdfgeteway.resp.EquityUnuseListResp;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;
import org.json.JSONObject;

public class EquityUnuseListCall extends YmatouBaseCall {

    private static String opurl = "equity/unusedList";

    public EquityUnuseListCall() {
        super(EnvSetup.getSystemUrl("cdfgeteway_iapi"), opurl, "POST", "JSON");
    }

    @Override
    public void addDefHeader() {
        client.addHeader("Accept",
                "text/xml,text/javascript,text/html,application/json");
        client.addHeader("Content-Type", "application/json; charset=UTF-8");
    }

    /**
     * 获取Code
     *
     * @return
     */
    public String getCode() {
        String Code = null;
        try {
            Code = new JSONObject(getReturnData()).optString("code");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Code;
    }

    /**
     * 获取BCode
     *
     * @return
     */
    public String getBCode() {
        String BCode = null;
        try {
            BCode = new JSONObject(getReturnData()).optString("bcode");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BCode;
    }

    /**
     * 获取Msg
     *
     * @return
     */
    public String getMsg() {
        String BCode = null;
        try {
            BCode = new JSONObject(getReturnData()).optString("msg");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BCode;
    }


    public EquityUnuseListResp getEquityUnuseListResp() throws Exception {

        Object result = new JSONObject(getReturnData());

        if (result.toString().equalsIgnoreCase("null"))
            return null;
        else
            return (EquityUnuseListResp) FormatUtil.GSONToObject(
                    new JSONObject(getReturnData()).toString(), EquityUnuseListResp.class);
    }
}
